<? require("adm_header.php"); ?>
<? writeCommonAdminTable(LA_ADMIN_ADVERTISER,1);?>

<!--START CONTENT -->
<p class="bg"><?=LA_ADMIN_ADVERTISER_MORE?></p>
<a href='adm_advertiser.php?new=1'><img src="../layout_images/add.gif" hspace="4" align="left" /><? echo LA_ADMIN_ADV_ADD; ?></a>
<? 

if ($_REQUEST["newchanged"])
{
	$c_name=$_REQUEST["c_name"];
	$c_email=$_REQUEST["c_email"];
	$c_pass=$_REQUEST["c_pass"];
	$c_id=$_REQUEST["c_id"];
	
	if (!$c_id)
	{
		$sql = "INSERT INTO `$adv_tbl` (`name`, `email`, `password`, `status`) VALUES ('$c_name', '$c_email', '$c_pass', '1')";
		$re = q($sql);
		$lastid=mysql_insert_id();
		echo formatString(LA_ADMIN_ADV_CREATED,array("$lastid")) . "<p />";
		
	}
	else 
	{
		$sql = "update $adv_tbl set name = '$c_name', email='$c_email', password='$c_pass' where id = $c_id";
		$re = q($sql);
		echo formatString(LA_ADMIN_ADV_UPDATED,array("$c_id")) . "<p />";
	}	

	
	
}
$id=$_REQUEST["id"];
if ($_REQUEST["status"] AND $_REQUEST["cmd"]==1)
{
	$sql = "update $adv_tbl set status = 1 where id = $id";
	$res = mysql_query($sql);
	
	$sql = "update $banner_tbl set status = 1 where cid = $id";
	$res = mysql_query($sql);
		
	echo LA_ADMIN_ADV_ACTIVE."<p />";
}
elseif ($_REQUEST["status"] AND $_REQUEST["cmd"]==0)
{
	
	$sql = "update $adv_tbl set status = 0 where id = $id";
	$res = mysql_query($sql);
	
	$sql = "update $banner_tbl set status = 0 where cid = $id";
	$res = mysql_query($sql);
		
	echo LA_ADMIN_ADV_NOT_ACTIVE."<p />";
}


if ($_REQUEST["delete"])
{
	$delete=$_REQUEST["delete"];
	$sql = "select * from $banner_tbl where cid = $delete";
	$r = q($sql);
	
	while ($row_banner=mysql_fetch_array($r))
	{
		$banner_name = $row_banner["filename"];	
		
		if (file_exists("$set_path/images/banners/$banner_name"))
		{
			unlink("$set_path/images/banners/$banner_name");
		}
	}
	
	$sql = "delete from $banner_tbl where cid = $delete";
	$r = q($sql);
		
	$sql = "delete from $adv_tbl where id = $delete";
	$re = q($sql)	;
	
	
}

$sql_adv = "select name,id,status from $adv_tbl";
$result = q ($sql_adv);
$advertisers = $result;




if ($advertisers > 0)
{
	print "<table bordercolor='#e6e6e6' cellspacing='0' cellpadding='3' width='100%' border='1'>";
	
     while ($row = mysql_fetch_array($result))
     {
             $name = $row["name"];
             $id = $row["id"];
             $status = $row["status"];
             
             if ($status == 1)
             {
             	$status = LA_ADMIN_ADV_ACT;	
				$cmd = "0";
             }
             else 
             {
             	$status = LA_ADMIN_ADV_DCT;
				$cmd = "1";
             }
	
	// Loop here...
	if ($color == "#f5f5f5")
	{
		$color = "#FFFFF";
	}
	else 
	{
		$color = "#f5f5f5";
	}
	print "<tr valign='center' bgcolor='$color'><td><a href='adm_advertiser.php?c_id=$id'>$name</a></td><td><a href='adm_banner.php?cid=$id'>".LA_ADMIN_ADV_ADD_BANNER."</a></td><td><a href='adm_advertiser.php?status=$status&id=$id&cmd=$cmd'>$status</a></td><td><a href='adm_advertiser.php?delete=$id'>".LA_ADMIN_ADV_DEL_USER."</a></td></tr>";
	
	// End loop
     }
	
	print "</table><p />";
}
else 
{
	print LA_ADMIN_ADV_NONE.  "<p />";	
}

?>




<?
if ($_REQUEST["new"] || $_REQUEST["c_id"])
{
	$c_id=$_REQUEST["c_id"];
	if ($c_id)
	{
		$sql = "select * from $adv_tbl where id = $c_id";
		$res = mysql_query($sql);
		$row = mysql_fetch_array($res);
		
		$c_name = $row["name"];
		$c_email = $row["email"];
		$c_pass = $row["password"];
		$c_status = $row["status"];
		
	}
	
	
	print "<form metod='post' action='adm_advertiser.php'><input type='hidden' name='c_id' value='$c_id'>";
	print "<b>".LA_ADMIN_ADV_ADD_MODIFY."</b><p />";
	print "<table bordercolor='#e6e6e6' cellspacing='0' cellpadding='3' width='100%' border='1'>";
	
	print "<tr valign='center' bgcolor='#f5f5f5'>
	<td>".LA_ADMIN_ADV_CLIENT_NAME.":</td><td><input type='text' name='c_name' value='$c_name' size='40' /></td></tr>";
	
	print "<tr valign='center' bgcolor='#fffff'>
	<td>".LA_ADMIN_ADV_CLIENT_EMAIL.":</td><td><input type='text' name='c_email' value='$c_email' size='40' /></td></tr>";
	
	print "<tr valign='center' bgcolor='#f5f5f5'>
	<td>".LA_ADMIN_ADV_CLIENT_PASS.":</td><td><input type='text' name='c_pass' value='$c_pass' size='40' /></td></tr>";
	
	
	
	print "<tr valign='center' bgcolor='#f5f5f5'>
	<td colspan='2'><input type='submit' name='newchanged' value='".LA_ADMIN_ADV_CRUP."' /></td></tr>";
	
	
	
	
	
	print "</table></form>";
}
?>

<!-- END CONTENT -->

<?
writeCommonAdminTable("Advertisers",""); 
require("adm_footer.php"); ?>